<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>添加页面</title>
    <script th:src="@{/js/jquery.min.js}"></script>
</head>
<body>

<h1>返乡防疫登记</h1>
<form th:action="@{/add}" th:object="${returnPerson}" method="post">
    <p>
        姓名：<input th:field="*{personName}" type="text">
    </p>
    <p>
        身份证：<input th:field="*{personId}" type="text">
    </p>
    <p>
        电话：<input th:field="*{personPhone}" type="text">
    </p>
    <p>
        出发城市：<input th:field="*{sendCity}" type="text">
    </p>
    <p>
        是否访谈：
        <select th:field="*{interviewStatus}">
            <option value="N">否</option>
            <option value="Y">是</option>
        </select>
    </p>
    <p>
        返乡日期：<input th:field="*{returnDate}" type="text">(yyyy-MM-dd)
    </p>
    <p>
        创建日期：<input th:field="*{createDate}" type="text">
    </p>
    <p>
        <input type="submit" value="保存">
        <input type="button" onclick="main()" value="返回">
    </p>
</form>

<script>
    function main() {
        location = '/list';
    }

    $(function () {
        $('form').submit(function () {
            let personName = $('#personName').val();

            if (personName == '') {
                alert("姓名不能为空,请重新输入！")
                return false;
            }

            let returnDate = $('#returnDate').val();
            if (returnDate == '') {
                alert("返乡日期不能为空,请重新输入！")
                return false;
            }
            var pattern = /^\d{4}-\d{2}-\d{2}$/;
            if (!pattern(returnDate)) {
                alert("日期的输入格式为yyyy-MM-dd！")
                return false;
            }
        })
    })
</script>
</body>
</html>